/*
 * @Author: hx 2542123711@QQ.com
 * @Date: 2024-12-11 20:19:40
 * @LastEditors: hx 2542123711@QQ.com
 * @LastEditTime: 2024-12-15 16:42:25
 * @FilePath: /class_thread/thread-cp/task.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include <iostream>
#include <vector>
#include<string>

using namespace std;

class Task
{
public:
    Task(int data1, int data2, char operation)
        : _data1(data1), _data2(data2), _op(operation), _result(0), _exitcode(0)
    {
    }

    int run()
    {
        switch (_op)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
        {
            if (_data2 == 0)
            {
                _exitcode = 1;
            }
            else
            {   
                _result = _data1 / _data2;
            }
        }
        break;
        }

        return _result;
    }

    string ProductorShow()
    {
        string tasks;
        tasks += to_string(_data1);
        tasks += _op;
        tasks += to_string(_data2);
        tasks += " =?";

        return tasks;
    }

    string ConsumerShow()
    {
        string tasks;
        tasks += to_string(_data1);
        tasks += _op;
        tasks += to_string(_data2);
        tasks += " = ";
        tasks += to_string(_result);
        tasks += "[_exitcode = ";
        tasks += to_string(_exitcode);
        tasks += ']';

        return tasks;
    }

private:
    int _data1;
    int _data2;
    char _op;
    int _result;
    int _exitcode;
};
